package com.wavecoler.professor.servlets;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import org.mortbay.log.Log;

import com.wavecoler.professor.dao.SessionDAO;
import com.wavecoler.professor.dao.ProblemDAO;
import com.wavecoler.professor.dao.TeamDAO;
import com.wavecoler.professor.objects.Session;

@SuppressWarnings("serial")
public class RegisterSessionServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Session s = new Session();

		/*
		 * String problemName = request.getParameterValues("problem")[0]; Long
		 * problemID = ProblemDAO.getProblemID(problemName);
		 * 
		 * s.setProblemID(problemID);
		 */

		s.setStatus("Ready");
		s.setProblemID(ProblemDAO.getProblemID(request.getParameterValues("problem")[0]));
		s.setSessionType(request.getParameterValues("sessiontype")[0]);
		s.setTimeLimit(Integer.parseInt(request.getParameter("timelimit")));
		if (s.getSessionType().contains("group")) {
			s.setParticipant(request.getParameterValues("group")[0]);
			/*WaveCreatorServlet w = new WaveCreatorServlet();
			w.createWave(GroupDAO.getGroupUsers(s.getParticipant()));*/
		} else if (s.getSessionType().contains("user")) {
			s.setParticipant(request.getParameterValues("user")[0]);
		}

		SessionDAO.insertSession(s);

		RequestDispatcher dispatcher = request
				.getRequestDispatcher("jsps/Index.jsp");
		dispatcher.forward(request, response);

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
}